package com.example.androidapp2;

import java.io.IOException;

import com.example.androidapp2.DbClasses.Utils;
import com.xyzdesa.droidnomy.R;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.Button;

public class PopUpConfirma extends Dialog {
	Button btnSi;
	Button btnNo;
	PopUpConfigu pupConfi;
	Context Ctx;
	DbAdapter DbConect;
	String Parent;
	int[] Valores;

	public PopUpConfirma(Context context, DbAdapter db, PopUpConfigu pup) {
		super(context);
		this.setContentView(R.layout.pup_confirma);

		btnSi = (Button) findViewById(R.id.btnSi);
		btnNo = (Button) findViewById(R.id.btnNo);
		Ctx = context;
		DbConect = db;		
		pupConfi = pup;

		final Dialog di = this;	
		btnNo.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {
				di.hide();
			}
		});
	}

	public void show(String parent, int[] valores)
	{
		Parent = parent;
		Valores = valores;		
		final Dialog di = this;

		SetTitle();
		btnSi.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {
				if(Parent.equals("Main")){
					DbConect.InactivarUltimo();
					((MainActivity)Ctx).ActualizarProgressBar();
					di.hide();
				}else if(Parent.equals("EliCategoria"))
				{
					DbConect.InactivarCategoria(Valores[0]);
					((MainActivity)Ctx).CargarSpinnerCategorias();
					di.hide();
				}else if(Parent.equals("ReestMes"))
				{
					DbConect.InactivarMes(Utils.GetFecha());
					((MainActivity)Ctx).ActualizarProgressBar();
					di.hide();
				}else if(Parent.equals("ReestAnio"))
				{
					DbConect.InactivarAnual(Utils.GetFecha());
					((MainActivity)Ctx).ActualizarProgressBar();
					di.hide();
				}else if(Parent.equals("ReestTodos"))
				{					
					DbConect.InactivarTodos();
					((MainActivity)Ctx).ActualizarProgressBar();
					di.hide();
				}else if(Parent.equals("Reset"))
				{					
					DbConect.DeleteDataBase();
					((MainActivity)Ctx).DBOpen();
					((MainActivity)Ctx).ActualizarProgressBar();
					if( DbConect.SetUltimoIngreso())
						((MainActivity)Ctx).pupConfi.Show();
					di.hide();
				}else if(Parent.equals("EliminarMov")){
					DbConect.InactivarPorId(Valores[0]);
					((MainActivity)Ctx).ActualizarProgressBar();
					di.hide();
				}
							
				if(DbConect.GetTotalMovimientos("In")==0)
					pupConfi.Show();
			}
		});
		super.show();
	}

	private void SetTitle()
	{
		if(Parent.equals("Main"))
			this.setTitle(R.string.btnDeshacer);			
		else if(Parent.equals("EliCategoria"))		
			this.setTitle(R.string.mnuElCategorias);
		else if(Parent.equals("ReestMes"))
			this.setTitle(R.string.itmMensual);
		else if(Parent.equals("ReestAnio"))
			this.setTitle(R.string.itmAnual);
		else if(Parent.equals("ReestTodos"))
			this.setTitle(R.string.itmTodos);
		else if(Parent.equals("EliminarMov"))
			this.setTitle(R.string.itmEliminar);
	}
}
